package com.example.casper.Experiment2024.share;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.bumptech.glide.Glide;
import com.example.casper.Experiment2024.R;

public class shareLocationsDetailActivity extends AppCompatActivity {

    private ImageView imageView;
    private TextView titleTextView, latitudeTextView, longitudeTextView, feelingTextView, provinceTextView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_share_location_detail);

        // 初始化视图组件
        imageView = findViewById(R.id.image_view_pic);
        titleTextView = findViewById(R.id.detailTitle);
        latitudeTextView = findViewById(R.id.text_view_latitude);
        longitudeTextView = findViewById(R.id.text_view_longitude);
        feelingTextView = findViewById(R.id.text_view_feeling);

        // 从 Intent 获取传递的数据
        Intent intent = getIntent();
        String locationName = intent.getStringExtra("locationName");
        double latitude = intent.getDoubleExtra("latitude", 0.0);
        double longitude = intent.getDoubleExtra("longitude", 0.0);
        String feeling = intent.getStringExtra("feeling");
        String province = intent.getStringExtra("province");
        String picPath = intent.getStringExtra("picPath");

        // 显示数据
        titleTextView.setText(locationName);
        latitudeTextView.setText("Latitude: " + latitude);
        longitudeTextView.setText("Longitude: " + longitude);
        feelingTextView.setText("Feeling: " + feeling);

        if (picPath != null) {
            Glide.with(this).load(Uri.parse(picPath)).into(imageView);
        } else {
            imageView.setImageResource(R.drawable.ic_launcher_background); // 默认图片
        }

        // 返回按钮
        Button backButton = findViewById(R.id.button_back_to_share);
        backButton.setOnClickListener(v -> finish());
    }
}
